import api.Flyweight;

import api.Impl.GoPieceFlyweight;

import java.util.HashMap;
import java.util.Map;

// 享元工厂：负责管理享元对象的创建和共享
class GoPieceFactory {
    private static final Map<String, Flyweight> flyweightMap = new HashMap<>();

    // 同一种颜色的棋子只会创建一次
    public static Flyweight getFlyweight(String color) {
        // 如果已有该颜色的棋子，直接返回；否则创建新的棋子
        if (!flyweightMap.containsKey(color)) {
            flyweightMap.put(color, new GoPieceFlyweight(color));
            System.out.println("创建新围棋棋子，颜色为: " + color);
        }
        return flyweightMap.get(color);
    }
}